package com.itheima.webaitliasserver.service.impl;

import com.itheima.webaitliasserver.mapper.DeptMapper;
import com.itheima.webaitliasserver.pojo.Dept;
import com.itheima.webaitliasserver.pojo.Result;
import com.itheima.webaitliasserver.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ClassName: xiaoZhang
 * @Description:
 * @Author: Zhang
 * @CreateDate: 2025-06-26 15:25
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    /**
    * @Author: Zhang
    * @param:        
    * @createTime: 2025/6/26 15:44
    * @Description: 查询部门列表
    * @Return: 无
    */
    @Override
    public List<Dept> queryDeptList() {
        List<Dept> depts = deptMapper.queryDeptListMapper();
        return depts;
    }

    @Override
    public void queryDeptById(Integer deptId) {
        deptMapper.deleteDeptById(deptId);
    }

    public String addDept(Dept dept) {
        System.out.println(dept.getName() + "部门");
        Dept deptLine = deptMapper.queryDeptByName(dept.getName());
        if(deptLine != null && deptLine.getName().equals(dept.getName())){
            return "部门已存在，请勿重复添加";
        }
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.addDept(dept);
        return "新增成功";
    }
}
